﻿$(document).ready(function () {
    if (!page.my) {
        page.commonUserControl = new NDUAP.Selector({ divID: "userId", typeID: 1, totalSelectNum: 1, quickBoxPositionX: -285, width: 150, searchData: page.userList });
        for (var i = 0; i < page.userList.length; i++) {
            if (page.userList[i].JobNumber == page.queryUserId) {
                page.commonUserControl.setValue([page.userList[i]]);
                break;
            }
        }
    }
    page.init();
});

var page = {
    pageIndex: 0,
    pageSize: 10,
    url: "/handler/reward.ashx?action=",
    popU: null,

    init: function () {
        $(".top-bar .right li:" + (page.my ? "eq(2)" : "first")).addClass("current");
        $("#btnTransfer").bind("click", page.showTransfer);
        page.query();
    },

    query: function (pageIndex) {
        var id = !page.my && page.commonUserControl.getValue().length > 0 ? page.commonUserControl.getValue()[0].id : 0;
        var type = $("input[name='type']:checked").val();
        var start = $("#start").val();
        var end = $("#end").val();
        var keyword = $("#keyword").val();
        var deptName = $.trim($("#deptName").val());

        if (pageIndex != undefined)
            page.pageIndex = pageIndex;

        $.get(page.url + "query", { my: page.my, deptName: deptName, userId: id, type: type, start: start, end: end, keyword: keyword, pageIndex: page.pageIndex, pageSize: page.pageSize, r: Math.random() }, function (data) {
            $("#result").html(TrimPath.processDOMTemplate("transaction", data));
            page.pager(data.count);
        }, "json");
    },

    pager: function (count) {
        if (count == 0) {
            $("#pagination").empty();
            return;
        }
        $("#pagination").pagination(count, {
            num_edge_entries: 2,
            num_display_entries: 10,
            current_page: page.pageIndex,
            items_per_page: page.pageSize,
            callback: page.query
        });
    }
};

